package com.job.ZhangMeng.Homework0705;

/**
 * 2022.07.05  自定义Student类
 * 张孟
 */

class Student{
    private String name;
    private long number;
    private int chineseScore;
    private int mathScore;
    private int javaScore;
    public int flag=1;

    public void show()
    {
        System.out.println("姓名："+this.name+"\t学号："+this.number);
        System.out.println("语文成绩："+this.chineseScore+"\t数学成绩："+this.mathScore+"\tJAVA成绩："+this.javaScore);
    }
    public void setBasicInfo(String name,long number)
    {
        this.name=name;
        this.number=number;
    }
    public void setScore(int c,int m,int j)
    {
        this.chineseScore=c;
        this.mathScore=m;
        this.javaScore=j;
    }
    public void showFlag()  //测试stu3=null时调用
    {
        System.out.println("stu3指向null时,flag="+flag);
    }

    public Student(){}  //无参构造方法
    public Student(String name,long number)    //含参构造方法1
    {
        this.name=name;
        this.number=number;
    }
    public Student(String name,long number,int cScore,int mScore,int jScore)    //重载，含参构造方法2
    {
        this.name=name;
        this.number=number;
        this.chineseScore=cScore;
        this.mathScore=mScore;
        this.javaScore=jScore;
    }
}

public class Homework0705_B {

    public static void main(String[] args) {
        Student stu1=new Student(); //调用无参构造方法
        stu1.setBasicInfo("李元浩", 2019412200L);
        stu1.setScore(96, 39, 100);
        stu1.show();
        System.out.println("--无参构造方法被调用--\n");

        Student stu2=new Student("史森明", 2022443579L);
        stu2.setScore(99, 100, 83);
        stu2.show();
        System.out.println("--含参构造方法1被调用--\n");

        Student stu3=new Student("张孟", 2021371202L,100, 78, 97);
        stu3.show();
        System.out.println("--含参构造方法2被调用--\n");

        stu3=null;
        stu3.showFlag();
        //Exception in thread "main" java.lang.NullPointerException
        //	at com.job.ZhangMeng.Homework0705.Homework0705_B.main(Homework0705_B.java:72)
    }

}
